﻿@using XinYi.CrookedShowMode;
@{
    //ProductSpuView productSpu = ViewBag.productSpu;
    //ProductSkuView productSku = ViewBag.ProductSku;
    //List<Pic> pics = ViewBag.pics;
    //string str = null;
    List<Brand> list1 =  ViewBag.List1;
    List<Category> list2 =  ViewBag.List2;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加产品</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="~/css/shop.css" type="text/css" rel="stylesheet" />
    <script src="~/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="~/js/jquery.cookie.js"></script>
    <script src="~/js/layer/layer.js" type="text/javascript"></script>
    <script src="~/js/laydate/laydate.js" type="text/javascript"></script>
    <link rel="stylesheet" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript"></script>

    @*<link rel="stylesheet" href="~/css/style.css" />*@
    <style type="text/css">
        /*body .layer-ext-myskin .layui-layer-content {

            overflow: hidden;

        }*/
        /*.layui-form-select {
            z-index: 1000;
        }*/

        .layui-form-item .layui-input-inline,
        .layui-input-block {
            width: 300px;
        }

        .layui-upload-img {
            transform: scale(0.8);
            -ms-transform: scale(0.8);
            -webkit-transform: scale(0.8);
            -o-transform: scale(0.8);
            -moz-transform: scale(0.8);
        }
    </style>

</head>
<body>
    <div class="column_title" id="title">添加产品</div>
    <div style="margin-top:5px">
        <div class="layui-form">
            <h3 style="margin-left:10px">添加商品信息</h3>
            <div style="border:1px solid  #eee; margin:10px;padding:10px">
                @*<input type="hidden" name="Id" value="@list1.Id" />*@
                <div class="layui-form-item">
                    <label class="layui-form-label">品牌列表：</label>
                    <div class="layui-input-inline">
                        <select name="BrandId" value="" lay-filter="brand" id="brand">
                            <option value="0" selected=selected>请选择</option>
                            @*@foreach (var item in list1)
                            {
                                <option value="@item.Id" >@item.Name</option>
                            }*@
                           
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品编码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Code"  required=required lay-verify="required" placeholder="" id="code1" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Name" id="sname" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                    </div>
                    <label class="layui-form-label">重量：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Weight"  id="aa1" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                    </div><span class="layui-form-mid layui-word-aux">g</span>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品分类：</label>
                    <div class="layui-input-inline" id="aaw">
                        <select name="OneCategoryId" value="" lay-filter="one" id="one">
                            <option value="0" selected id="oone">请选择</option>                     
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="TwoCategoryId" value="" lay-filter="two" id="two">
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="ThreeCategoryId" value="" lay-filter="three" id="three">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-block">                          
                        <input name="PublishStatus" id="publish_Status" title="上架" type="checkbox" lay-skin="primary"/>
                        <input name="AuditStatus" id="audit_Status" title="审核" type="checkbox" lay-skin="primary" />                     
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述：</label>
                    <div class="layui-input-block" style="width:1000px;">
                        <textarea class="layui-textarea" name="Descript" id="LAY_demo1"></textarea>
                    </div>
                </div>
                @*<div class="layui-form-item">
                    <div class="layui-input-block">
                        @if (productSpu.Id > 0)
                        {
                            <button class="layui-btn" lay-submit=lay-submit lay-filter="UpdProductSpu">编辑商品</button>
                        }
                        else
                        {
                            <button class="layui-btn" lay-submit=lay-submit lay-filter="AddProductSpu">添加商品</button>
                        }

                    </div>
                </div>*@
            </div>
        </div>
        <div class="layui-form">
            <h3 style="margin-left:10px">添加商品规格sku</h3>
            <div style="border:1px solid  #eee; margin:10px;padding:10px">
                
                <div class="layui-form-item">
                    <label class="layui-form-label">价格：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Price" value="" id="pirce" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                    </div><span class="layui-form-mid layui-word-aux">元</span>
                    <label class="layui-form-label">库存：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Stock" value="" id="kucun" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                    </div><span class="layui-form-mid layui-word-aux">件</span>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品图片：</label>
                    <div class="layui-input-block " style="width:1200px">
                        <div class="layui-upload">


                            <button class="layui-btn" id="test2" type="button">多图片上传</button>


                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                预览图：
                                <div class="layui-upload-list" id="demo2"></div>
                            </blockquote>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit=lay-submit lay-filter="AddProductSku">提交</button>
                    </div>
                </div>
            </div>
        </div>
        


    </div>
</body>
</html>

<script type="text/javascript">
   
    layui.use(['upload', 'form', 'layedit', 'layer'], function () {
        var upload = layui.upload,
            form = layui.form,
            layer = layui.layer;

        //品牌下拉框
        select("/Brand/GetBrandToList", "#brand");
        //一级分类下拉框
        select(("/Products/GetLeveCategoryList?leve=" + 1), "#one");
        //二级分类下拉框
        select(("/Products/GetLeveCategoryList?leve=" + 2), "#two");
        //三级分类下拉框
        select(("/Products/GetLeveCategoryList?leve="+3), "#three");
        //分类菜单下拉框
        select("/Product/GetCategory", "#Category");
        //商品列表下拉框
        select("/Product/GetProducts", "#ProductSpu");
        $("#aaw").mouseout(function () {
           
            if ($("#one").val() != 0) {
               
            }
        });
        
        //设置规格
        $(window).one("resize", function () {
            $("#Spsc").click(function () {
                var index = layui.layer.open({
                    title: "设置规格",
                    type: 2,
                    content: "/Product/Spec",
                    success: function (layero, index) {
                        setTimeout(function () {
                            layui.layer.tips('点击此处返回添加商品', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        }, 500)
                    }
                })
                layui.layer.full(index);
            })
        }).resize();
        //下拉框绑定方法
        function select(url, name) {
            $.ajax({
                url: url,
                type: "post",
                datatype: "Json",
                success: function (result) {
                    var option;
                    for (var i = 0; i < result.length; i++) {
                        option += "<option value=" + result[i].Id + ">" + result[i].Name + "</option>";
                    }
                    $(name).append(option);
                    form.render();
                }
            });
        }

        /////监听下拉框操作
        //form.on('select(one)', function (data) {
        //    var sid = data.value;
        //    $("#two").html("");
        //    select("/Product/GetLeveCategory?parentId=" + sid + "&leve=2", "#two");
        //});
        //form.on('select(two)', function (data) {
        //    var sid = data.value;
        //    $("#three").html("");
        //    select("/Product/GetLeveCategory?parentId=" + sid + "&leve=3", "#three");
        //});      
    });

    $(".layui-btn").click(function () {
        var value1 = $("#brand").val();
        var value2 = $("#one").val();
        var datas = {};
        if (value1 == 0) {

        } else if (value2 == 0) {

        } else {
            datas.BrandId=$("#brand").val();//获取品牌ID
            datas.BrandName=$("#brand").find("option:selected").text();//获取品牌名称
            datas.Code = $("#code1").val();                   //获取商品编码
            datas.Product_SpuName = $("#sname").val();         //获取商品名称
            datas.Weight = $("#aa1").val();                       //获取重量
            datas.One = $("#one").val();    //一级分类
            datas.Two = $("#two").val();   //二级分类
            datas.Three = $("#three").val();//三级分类    
            //datas.one = $("#one").find("option:selected").text();    //一级分类
            //datas.two = $("#two").find("option:selected").text();    //二级分类
            //datas.three = $("#three").find("option:selected").text();//三级分类            
            datas.Descript = $("#LAY_demo1").val();               //描述
            datas.Price = $("#pirce").val();                        //价格
            datas.Stock = $("#kucun").val();                        //库存
            if ($("#publish_Status").prop('checked')) {
                 datas.Publish_Status = 1;          //是否上架 1是0否
            } else {
                 datas.Publish_Status = 0;
            }
            if ($("#audit_Status").prop('checked')) {
                datas.Audit_Status = 1;             //是否审核 1是0否
            } else {
                datas.Audit_Status = 0;
            }
            $.ajax({
                url: "/Products/AddProduct_SpuInfo",
                data: datas,
                type: "Post",
                success: function (data) {
                    if (data.Success) {
                        //layer.msg("添加成功", { icon: 1, time: 2500, title: "提示框" });
                        layer.msg("添加成功");
                        window.location.href = '/Home/Shops_index';
                    }
                    else {
                        layer.msg("添加失败", { icon: 1, time: 2500, title: "提示" });
                    }
                }
            });
        }
       
    });
</script>